<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html>
<html lang="zh_cn">
<head>
 	<title>投票详细</title>
    <style type="text/css">
    	.checkbox label{
    		padding-left: 0;
    	}
    	.radio label{
    		padding-left: 0;
    	}
    </style>
</head>
<body>
	<data id="info" nav="vote" menu="voteDetail" service="投票服务" action="投票详细">
    <div class="row wrapper white-bg animated slideInRight min-height">
	    <div class="row">
	      <div class="col-lg-12">
	          <div class="ibox float-e-margins">
	              <div class="ibox-title">
	                  <h5>投票操作<small class="text-navy"> 在这里你可以进行投票操作</small></h5>
	                  <div class="ibox-tools">
	                      <a class="collapse-link">
	                          <i class="fa fa-chevron-up"></i>
	                      </a>
	                      <a href="#" data-toggle="dropdown" class="dropdown-toggle">
	                          <i class="fa fa-wrench"></i>
	                      </a>
	                      <ul class="dropdown-menu dropdown-user">
	                          <li><a href="#">Config option 1</a>
	                          </li>
	                          <li><a href="#">Config option 2</a>
	                          </li>
	                      </ul>
	                      <a class="close-link">
	                          <i class="fa fa-times"></i>
	                      </a>
	                  </div>
	              </div>
	              <div class="ibox-content">
	                  <form class="form-horizontal" method="post" id="voteForm" action="">
	                  	<div class="row">
							<div class="form-group">
								<label class="col-sm-5 control-label">投票标题</label>
								<div class="col-sm-5">
									<p class="form-control-static" name="title" id="title">${voteDetail[0].title}</p>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-5 control-label">
									投票类型
								</label>
								<div class="col-sm-5">
									<p class="form-control-static" name="type" id="type">${voteDetail[0].type}</p>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-5 control-label">
									投票隐私
								</label>
								<div class="col-sm-5">
									<p class="form-control-static" name="scope" id="scope">${voteDetail[0].scope }</p>
								</div>
							</div>
							
							<div class="form-group">
								<label class="col-sm-5 control-label">投票截止时间</label>
								<div class="col-sm-5">
									<p class="form-control-static" name="deadline" id="deadline">${voteDetail[0].deadline }</p>
								</div>
							</div>
							<c:forEach items="${voteDetail}" var="detail" varStatus="status">
								<div class="form-group">
									<label class="col-sm-5 control-label"> ${status.index==0?'投票选项 ':''}</label>
									<div class="col-sm-5">
										<div class="${detail.type=='单选'?'radio':'checkbox'}  i-checks">
											<label>
												<div class="${detail.type=='单选'?'iradio_square-green':'icheckbox_square-green'}"
													style="position: relative;">
													<input type="${detail.type=='单选'?'radio':'checkbox'}" value="${detail.oid}"
														style="position: absolute; opacity: 0;"
														name="${detail.type=='单选'?'oid':'oids'}">
													<ins class="iCheck-helper"
														style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; background: rgb(255, 255, 255) none repeat scroll 0% 0%; border: 0px none; opacity: 0;"></ins>
												</div> <i></i> ${detail.content}
											</label>
										</div>
									</div>
								</div>
							</c:forEach>
							</div>
							<div class="ibox-content">
								<div class="form-group " id="savePart">
			                        <div class="col-sm-5 col-sm-offset-5">
			                            <button type="button" class="btn btn-primary" id="save">投票</button>
			                            <button type="reset" class="btn btn-white">取消</button>
			                        </div>
			                    </div>
			                 </div>
						</form>
					</div>
   				</div>
   			</div>
	 	</div>
	</div>
	<js>
	    <!-- laypage -->
		<script type="text/javascript" src="${ctx}/resource/laypage/laypage.js"></script>
		<script type="text/javascript" src="${ctx}/resource/laypage/laytpl.js"></script>
	
	    <!-- iCheck -->
	    <script src="${ctx}/resource/v2/js/icheck.min.js"></script>
	    <!-- layer js -->
	    <script src="${ctx}/resource/v2/layer/layer.js"></script>
	    <script>
	        
	         $(document).ready(function () {
	            $('.i-checks').iCheck({
	                checkboxClass: 'icheckbox_square-green',
	                radioClass: 'iradio_square-green',
	            });
	        });
	        
	        
	        $(document).ready(function(){
	        	$("#save").click(function(){
	        		var load = layer.load(0);
		        	jQuery.ajax({
		        		type: "post",
		        		url: "${ctx}/vote/voteAction.do",
		        		data: jQuery("#voteForm").serialize()+"&tid=${param.topicId}",
		        		dataType:"json",
		        		success:function(data){
		        			layer.close(load);
		        			if(data.flag=="success"){
	    						layer.msg(data.message, {time: 1000, icon:6});
	        					window.location.href="${ctx}/vote/router/route.do?topicId=${param.topicId}";
	    					}else{
	    						layer.msg(data.message, {time: 1000, icon:6});
	    					}
		        		},
						error:function(data){
							layer.close(load);
							alert(JSON.stringify(data));
							window.location.href="${ctx}/vote/router/route.do?topicId=${param.topicId}";
						}
		        	});
	        	});
	        })
	        
	    </script>
    </js>
</body>
</html>
